(function($) {
   $.common = {};
   //js静态变量
   $.common.Constants ={
		   arts             : '0',//文科
		   science          : '1'//理科
   }
   $.common.alert ={
	    success:function(alertMsg){
	        swal('系统提示',alertMsg,  "success");
	    },
	    error:function(alertMsg){
	    	swal('系统提示',alertMsg,  "error");
	    },
	    choose:function(msg,callback){
	    	swal({  
	    		title: "你确定要操作吗?",
	    		text: msg, 
	    		type: "warning", 
	    		showCancelButton: true, 
	    		confirmButtonColor: "#DD6B55",  
	    		confirmButtonText: "确定", 
	    		cancelButtonText:"取消",
	    		closeOnConfirm: false,
	    		closeOnCancel: false
	    		}, 
	    		callback);
	    },
	    //guide: 指引方向（0：上，1：右，2：下，3：左）。
	    tips:function(html, follow, parme){
	        layer.tips(html, follow, parme);
	    },
	    dom:function(context,closeCallback){
	        $.layer({
	            type: 1,
	            shade: [0.1, '#000',19900322],
	            closeBtn: [0],
	            title: false,
	            border: false,
	            shadeClose: true,
	            page: {dom : context},
	            close: closeCallback
	        })
	    }
	};
   
	//////////////////////////////jquery公用方法
	$.getAsyncHtmlData = function(url, data) {
		var htmlData =null;
		$.ajax({
			type : "post",
			url : url,
			async : false,
			data : arguments[1] || {},
			success : function(result) {
				htmlData = result;
			},
			error : function(result) {
				htmlData = result;
			}
		});
		return htmlData;
	};
	
	$.event.special.inputchange = {
		    setup: function() {
		        var self = this, val;
		        $.data(this, 'timer', window.setInterval(function() {
		            val = self.value;
		            if ( $.data( self, 'cache') != val ) {
		                $.data( self, 'cache', val );
		                $( self ).trigger( 'inputchange' );
		            }
		        }, 20));
		    },
		    teardown: function() {
		        window.clearInterval( $.data(this, 'timer') );
		    },
		    add: function() {
		        $.data(this, 'cache', this.value);
		    }
	};
	
	//select初始化
	$.fn.selectInit = function(options) {
		var that = this;
		$(this).empty();
		if (options.defaults) {
			$(this).append(
					"<option value=" + options.defaults.key + ">" + options.defaults.value
							+ "</option>");
		}

		var key = "id", value = "text";
		if (options.mapping) {
			key = options.mapping.key;
			value = options.mapping.value;
		}
		
		$(options.data).each(function(num, item) {
			var $d1 = $("<option value='" + item[key] + "'>" + item[value] + "</option>");
		    $d1.data("optionData", item);
		    $(that).append($d1);
		});
		$(this).bind("change", options.onChange);
		return this;
	};
	
	
	$.fn.showbox = function(options){
		// var $height = window.screen.availHeight ;
		// var $width = window.screen.availWidth;
		var $height = $(window).height();
		var $width = $(window).width();
		var $w = parseInt($width - $(this).width() ) / 2;
		var $h = parseInt($height - $(this).height() ) / 2;
		var data = {};
		data.zindex = 8000;
		data.top = $h;
		data.left = $w;
		data = $.extend(data,options);    
		var $htmls = "<div class='showbox' style='position:fixed;top:0;left:0;background:rgba(255,255,255,0.40)!important;z-index:"+data.zindex+";background-color:#000; filter:alpha(opacity=70);";
		$htmls += "width:" + $width + "px;height:" + $height + "px;'></div>";
		$("body").append($htmls);
		$(this).css({ "top":data.top + "px", "left":data.left + "px" });
		$(this).show();
	};
	
	$.newWindow = function(url){
	    return window.open(url);
	};
})(jQuery);

//////////////////////////////////////////js方法扩展区

String.prototype.trim = function() {
    return this.replace(/(^\s+)|\s+$/g, "");
};

/**
 * 转换字符串为json对象
 */
String.prototype.toJson = function() {
    return eval('(' + this + ')');
};

String.prototype.endsWithIgnoreCase = function(str) {
    return (this.toUpperCase().match(str.toUpperCase() + "$") == str.toUpperCase()) ||
    (this.toLowerCase().match(str.toLowerCase() + "$") == str.toLowerCase());
}

Array.prototype.remove=function(dx){
  if(isNaN(dx)||dx>this.length){return false;}
  for(var i=0,n=0;i<this.length;i++){
      if(this[i]!=this[dx]){
          this[n++]=this[i];
      }
  }
  this.length-=1;
};

function getAjaxData(fromId){
	var formArray = $("#"+fromId).serializeArray();
	var data = {};
	for(var i =0;i<formArray.length;i++){
		data[formArray[i].name] = formArray[i].value;
	}
	return data;
}

/**
 * 头部菜单加载
 * @param secondTreeIndex 默认选中第几个耳机菜单
 * @param sfyc 是否显示二级菜单 1表示显示，其它不显示
 */
function headInit(secondTreeIndex,sfyc){
	  //加载头部
    $.ajax({
		url:'stu_new_head.html',
		//url:'hfjy_head.html',
        type:'get',
        dataType:'html',
        async: false,
        success:function (data){
            $(".navbar-fixed-top").append(data); //填充头部到页面
            //$(".head-top").append(data); //填充头部到页面
            //$('.nav-right-bar li a').eq(4).addClass('active');
            window.tokenMatching();

           // window.headhover();
            $('.have-voluntar').addClass('active');
            if(sfyc==1){
            	$('.main-nav-voluntar').show();
                $('.main-nav-submenu ul li a').eq(secondTreeIndex).addClass('active');
            }
            
        }
    });
}

//检查志愿填报菜单下的二级菜单是否直接通过地址访问，若通过地址直接访问，则需要跳转到个人信息填写页面。
function redirectFirstPage(){
	
	var urlType= $.url().param("urlType");
	
	//默认赋值已选择的地区
    $.ajax({
        url:'../../markposition/checkUrl',
        type:'get',
        dataType:'json',
        async: false,
        success:function (data){
        	var url="evr_score_estimate.html";
        	//urlTyp不为空，表示基本信息填写之后，要定位的二级菜单
        	if(typeof(urlType) != "undefined"&&urlType){
        		url+="?urlType="+urlType;
        	}
        	if(data.success){
        		if(!data.data){
        			location.href=url; 
        		}
        	}else{
        		location.href=url; 
        	}
        }
      });
}

/**
 * 手机端禁掉支付功能
 * @param type 1：查看更多入口 2：购买
 */
function phoneFilter(type){
	if(!fn_isPC()){
		$.common.alert.error(type == 1 ? "Sorry，请使用PC访问zy.hfjy.com查看更多报告内容" : "Sorry，请使用PC访问zy.hfjy.com购买和学习高考志愿课程");
		return true;
	}else{
		return false;
	}
}

/**
 * 没登录弹出登陆框
 */
function loginInit(){
	var result = $.getAsyncHtmlData("../../user/getUserInfo");
	var uname = result.data.name;
    if (typeof(uname) == "undefined" || uname == "") {
    	$(".studentLogin").addClass("animated down").fadeIn();
    	otherlogin();
    	return false;
    }
    return true;
}


/**
 * 没登录弹出登陆框
 */
function loginInitFirstPage(){
	var result = $.getAsyncHtmlData("../../user/getUserInfo");
	var uname = result.data.name;
    if (typeof(uname) == "undefined" || uname == "") {
    	location.href = "evr_score_estimate.html";
    }
}


/////////////////////////////////////////全局包装的方法区
/**
 * 引入css、script文件
 * @param {Object} file
 */
function include(file) {
    var files = typeof file == "string" ? [file] : file;
    for (var i = 0; i < files.length; i++) {
        var name = files[i].replace(/^\s|\s$/g, "");
        var att = name.split('.');
        var ext = att[att.length - 1].toLowerCase();
        var isCSS = ext == "css";
        var tag = isCSS ? "link" : "script";
        var attr = isCSS ? " type='text/css' rel='stylesheet' " : " language='javascript' type='text/javascript' ";
        var link = (isCSS ? "href" : "src") + "='" + '' + name + "'";
        if ($(tag + "[" + link + "]").length == 0) {
            $("<" + tag + attr + link + "></" + tag + ">").appendTo('head');
        }
    }
}


